#include <QtGui>
#include <QApplication>
#include <QFileSystemModel>
#include <QProgressDialog>
#include <QMessageBox>

#include <stdexcept>

#include "treeView.h"
#include "copyThread.h"

typedef QSharedPointer<QProgressDialog> QProgressDialogPtr;

TreeView::TreeView(QWidget *parent) :
    QTreeView(parent)
{
    setAcceptDrops(true);
}

void TreeView::dragEnterEvent(QDragEnterEvent *event)
{
    TreeView *source = qobject_cast<TreeView *>(event->source());
    if (source && source != this) {
        event->setDropAction(Qt::MoveAction);
        event->accept();
    }
}

void TreeView::dragMoveEvent(QDragMoveEvent *event)
{
    TreeView *source = qobject_cast<TreeView *>(event->source());
    if (source && source != this) {
        QMouseEvent mEvent(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
        this->mousePressEvent(&mEvent);
        event->setDropAction(Qt::MoveAction);
        event->accept();
    }
}

void TreeView::dropEvent(QDropEvent *event)
{
    TreeView *source = qobject_cast<TreeView *>(event->source());
    if (source && source != this) {

        QString pathFrom = getItemPath(source);
        QString pathTo = getItemPath(this);

        emit dragDropPaths(pathFrom, pathTo);
    }
}

QString TreeView::getItemPath(QTreeView* obj)
{
    if(obj){
        QFileSystemModel model;
        QString path = model.filePath(obj->currentIndex());
        return path;
    }
    else{
        return QString("");
    }
}



